package com.example.javawebdemo.dao;//package com.example.javawebdemo.dao;
//
//import com.example.javawebdemo.models.User;
//import com.example.javawebdemo.jdbc.JDBCTemplateSingleton;
//import com.example.javawebdemo.utils.PasswordUtils;
//import org.springframework.dao.EmptyResultDataAccessException;
//import org.springframework.jdbc.core.BeanPropertyRowMapper;
//import org.springframework.jdbc.core.RowMapper;
//
//import java.sql.SQLException;
//import java.time.LocalDateTime;
//
//public class UserDAO {
//    private static final RowMapper<User> USER_ROW_MAPPER = new BeanPropertyRowMapper<>(User.class);
//
//    public boolean registerUser(User user) throws SQLException {
//        String sql = "INSERT INTO users (username, password, email, phone, created_at) " +
//                "VALUES (?, ?, ?, ?, ?)";
//        return JDBCTemplateSingleton.getJdbcTemplate().update(sql,
//                user.getUsername(),
//                PasswordUtils.hashPassword(user.getPassword()),
//                user.getEmail(),
//                user.getPhone(),
//                LocalDateTime.now()) > 0;
//    }
//
//    public User findByUsername(String username) throws SQLException {
//        String sql = "SELECT id, username, password, email, phone, created_at " +
//                "FROM users WHERE username = ?";
//        try {
//            return JDBCTemplateSingleton.getJdbcTemplate().queryForObject(
//                    sql, USER_ROW_MAPPER, username);
//        } catch (EmptyResultDataAccessException e) {
//            return null; // 查询无结果时返回null
//        }
//    }
//}

import com.example.javawebdemo.models.User;
import java.sql.SQLException;
public interface UserDAO {
    boolean registerUser(User user) throws SQLException;
    User findByUsername(String username) throws SQLException;
}